package com.pand.mysql.service;

import com.pand.mysql.model.Order;
import org.aspectj.weaver.ast.Or;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * Created by lh on 2017/11/8.
 */
@Repository("orderService")
public interface OrderService extends JpaRepository<Order, Long> {
    @Query("select o from Order o " +
            "where o.license = ?1 " +
            "and ((o.createTime <= ?2 and o.retTime >= ?2) " +
            "or (o.createTime <= ?3 and o.retTime >= ?3) " +
            "or (o.createTime > ?2 and o.retTime < ?3))")
    Optional<Order> findOrderByLicenseAndTime(String license, Date startTime, Date endTime);

    @Query("select distinct vin from Order ")
    List<String> findVins();

    Optional<Order> findFirstByVin(String vin);
}
